package ro.romanescu.useradmin.hibernate;

import java.io.Serializable;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import ro.romanescu.useradmin.IRole;
import ro.romanescu.useradmin.IUser;
import ro.romanescu.useradmin.IUserAttribute;

/**
 * Users management functionality.
 */
public class User implements IUser, Serializable
{
  private long id;
  private String username;
  private String password;

  private Date creationDate;
  private User author;
  
  private Date lastModificationDate;
  private User lastModificationAuthor;
  
  private List<IRole> roles = new ArrayList<IRole>();
  private List<IUserAttribute> attributes = new ArrayList<IUserAttribute>();
  
  private boolean audit;


  public void setId( long param ) {
    this.id = param;
  }

  public long getId() {
    return id;
  }

  public void setUsername( String param ) {
    this.username = param;
  }

  public String getUsername() {
    return username;
  }

  public void setPassword( String param ) {
    this.password = param;
  }

  public String getPassword() {
    return password;
  }

  public void setCreationDate( Date param ) {
    this.creationDate = param;
  }

  public Date getCreationDate() {
    return creationDate;
  }

  public void setAuthor( User param ) {
    this.author = param;
  }

  public User getAuthor() {
    return author;
  }

  public void setLastModificationDate( Date param ) {
    this.lastModificationDate = param;
  }

  public Date getLastModificationDate() {
    return lastModificationDate;
  }

  public void setLastModificationAuthor( User param ) {
    this.lastModificationAuthor = param;
  }

  public User getLastModificationAuthor() {
    return lastModificationAuthor;
  }

  public void setRoles( List<IRole> param ) {
    this.roles = param;
  }

  public List<IRole> getRoles() {
    return roles;
  }

  public void setAttributes( List<IUserAttribute> param ) {
    this.attributes = param;
  }

  public List<IUserAttribute> getAttributes() {
    return attributes;
  }

  public void setAudit( boolean param ) {
    this.audit = param;
  }

  public boolean isAudit() {
    return audit;
  }


  @Override
  public boolean equals( Object object ) {
    if( this == object ) {
      return true;
    }
    if( !( object instanceof User ) ) {
      return false;
    }
    final User other = ( User )object;
    if( id != other.id ) {
      return false;
    }
    if( !(username == null ? other.username == null : username.equals(other.username)) ) {
      return false;
    }
    if( !(password == null ? other.password == null : password.equals(other.password)) ) {
      return false;
    }
    if( !(creationDate == null ? other.creationDate == null : creationDate.equals(other.creationDate)) ) {
      return false;
    }
    if( !(author == null ? other.author == null : author.equals(other.author)) ) {
      return false;
    }
    if( !(lastModificationDate == null ? other.lastModificationDate == null : lastModificationDate.equals(other.lastModificationDate)) ) {
      return false;
    }
    if( !(lastModificationAuthor == null ? other.lastModificationAuthor == null : lastModificationAuthor.equals(other.lastModificationAuthor)) ) {
      return false;
    }
    if( !(roles == null ? other.roles == null : roles.equals(other.roles)) ) {
      return false;
    }
    if( !(attributes == null ? other.attributes == null : attributes.equals(other.attributes)) ) {
      return false;
    }
    if( audit != other.audit ) {
      return false;
    }
    return true;
  }

  @Override
  public int hashCode() {
    final int PRIME = 37;
    int result = 1;
    result = PRIME * result + (int) (id ^ (id >>> 32));
    result = PRIME * result + ((username == null) ? 0 : username.hashCode());
    result = PRIME * result + ((password == null) ? 0 : password.hashCode());
    result = PRIME * result + ((creationDate == null) ? 0 : creationDate.hashCode());
    result = PRIME * result + ((author == null) ? 0 : author.hashCode());
    result = PRIME * result + ((lastModificationDate == null) ? 0 : lastModificationDate.hashCode());
    result = PRIME * result + ((lastModificationAuthor == null) ? 0 : lastModificationAuthor.hashCode());
    result = PRIME * result + ((roles == null) ? 0 : roles.hashCode());
    result = PRIME * result + ((attributes == null) ? 0 : attributes.hashCode());
    result = PRIME * result + (audit ? 0 : 1);
    return result;
  }
}
